$(function() {
    var host = "admin.comment.sohu.com";
    var editurl = "http://" + host + "/editComment.action?commentId=";
    var disableurl = "http://" + host + "/disableComment.action?commentId=";
    var flushurl = "http://" + host + "/cache/flush.jsp?topicId=";
    var topicId;
    var url = document.URL;
    var pattern = /.*\/s(\d+)\.html.*/;
    var match = pattern.exec(url);
    if (match) {
        topicId = match[1];
    }

    $("#SOHUcomment").find("div[data-commentid]").each(function(i) {
        var commentId = $(this).attr("data-commentid");
        $(this).data("prepend", true);
        var addcontent = $("<a>", {
            href : editurl + commentId,
            target : "_blank",
            style : 'position: relative;',
            text : "编辑"
        }).after(" | ").after($("<a>", {
            href : disableurl + commentId,
            target : "_blank",
            style : 'position: relative;',
            text : "删除"
        })).after(" | ");
        
        if ($(this).hasClass("box")) {
            $(this).find("div.r > h5 span.feed-set").prepend(addcontent);
        } else {
            var feedset = $(this).find("h5 span.feed-set");
            $(feedset.get(feedset.length - 1)).prepend(addcontent);
        }

    });
    
    $("div.label").append($("<a>", {
        href : flushurl + topicId,
        text : "清空本新闻缓存",
        target : "_blank",
        style : "margin-left: 15px;"
    }));
    
    chrome.extension.sendRequest({
        action : "page"
    });

});